<?php

class ListingBehavior extends CActiveRecordBehavior {
	
	public function afterSave($event) {
//		$owner = $this->owner;
//		$goods = GoodsAgentRelated::model()->findByAttributes(array('goods_id'=>$owner->id));
//		if($owner->listing_status == 'ST_DELISTING'){
//			$goods->listing_status = 'ST_DELISTING';
//			$goods->save();
//		}
	}

	public function beforeValidate($event) {
		$owner = $this->owner;
		if ($owner->listing_status == 'ST_LISTING')
			$owner->listing_time = date('Y-m-d H:i:s');
	}
	
	public function listing() {
		$model = $this->owner;
		$criteria = $this->owner->getDbCriteria();
		$criteria->join = 'left join v_goods_agentable as v on (t.id = v.goods_id)';
		$criteria->compare('t.listing_status','ST_LISTING');
		$criteria->compare('t.status','ST_PASSED');
		$criteria->addCondition('v.id IS NOT NULL');
		$criteria->group = 't.id';
		return $model;
	}
}

?>